﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyPoints.UserControls
{
  /// <summary>
  /// Interaction logic for UrlTextBlock.xaml
  /// </summary>
  public partial class UrlTextBlock : UserControl
  {
    #region Dependency property Text
    ///<summary>
    /// Local field for dependency property.
    ///</summary>
    public static readonly DependencyProperty TextProperty =
      DependencyProperty.Register("Text", typeof(string), typeof(UrlTextBlock));

    ///<summary>
    /// Sets/gets Text value. Default value is null.      
    ///</summary>
    public string Text
    {
      get { return (string)GetValue(TextProperty); }
      set { SetValue(TextProperty, value); }
    }
    #endregion Dependency property Text


    #region Dependency property NavigateUrl
    ///<summary>
    /// Local field for dependency property.
    ///</summary>
    public static readonly DependencyProperty NavigateUrlProperty =
      DependencyProperty.Register("NavigateUrl", typeof(string), typeof(UrlTextBlock));

    ///<summary>
    /// Sets/gets NavigateUrl value. Default value is null.      
    ///</summary>
    public string NavigateUrl
    {
      get { return (string)GetValue(NavigateUrlProperty); }
      set { SetValue(NavigateUrlProperty, value); }
    }
    #endregion Dependency property NavigateUrl


    public UrlTextBlock()
    {
      InitializeComponent();
    }

    private void txtLink_RequestNavigate(object sender, RequestNavigateEventArgs e)
    {
      //Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
      Go();
      e.Handled = true;
    }

    private void txtLink_Click(object sender, RoutedEventArgs e)
    {
      Go();
      e.Handled = true;
    }

    private void Go()
    {
      var p = new ProcessStartInfo(this.NavigateUrl);
      Process.Start(p);
    }
  }
}
